NTP时间同步服务器客户端、服务端的安装以及配置文件的配置 |
您所在的位置:网站首页 › linux ntp客户端配置自动更新 › NTP时间同步服务器客户端、服务端的安装以及配置文件的配置 |
NTP(Network Time Protocol)服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,应用于对时间实时性要求高的、必须统一时间事件。 服务端安装 一、安装ntp服务 yum install ntp ntpdate -y 二、修改ntp.conf配置文件 cp /etc/ntp.conf /etc/ntp.conf.bak #对ntp.conf文件进行备份修改ntp.conf 配置文件如下: # For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). #记录时间差异的文件存放位置 driftfile /var/lib/ntp/drift # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default kod nomodify notrap nopeer noquery #我们对于默认的客户端拒绝所有的操作 restrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. #开启内部递归网络接口lo 即允许本机地址一切的操作 restrict 127.0.0.1 restrict -6 ::1 #我们允许局域网内所有客户端连接到这台服务器同步时间. #但是拒绝让他们修改服务器上的时间 # Hosts on local network are less restricted. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap service 192.168.75.132 # 这句也是手动增加的,指明局域网中作为NTP服务器的IP # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # 互联网上的三个ntp服务器。server用来指定要同步的时间服务器的ip地址 # 如果局域网环境下,注释掉下面默认的网络服务器地址,改成自己的局域网时间服务器IP地址 # 其中后面perfer表示优先,常用的有iburst,burst) server 0.rhel.pool.ntp.org server 1.rhel.pool.ntp.org server 2.rhel.pool.ntp.org #sebroadcast 192.168.1.255 autokey # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 autokey # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 autokey # manycast client # Undisciplined Local Clock. This is a fake driver intended for backup # and when no outside source of synchronized time is available. #如果server指定的服务器无法使用,就使用本机时钟作为ntp服务时间来源 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 # Enable public key cryptography. #crypto #设定包含的配置文件子文件 includefile /etc/ntp/crypto/pw # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. # 当进行秘钥方式进行认证的时候需要的文件 keys /etc/ntp/keys # Specify the key identifiers which are trusted. #trustedkey 4 8 42 # Specify the key identifier to use with the ntpdc utility. #requestkey 8 # Specify the key identifier to use with the ntpq utility. #controlkey # Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats对配置文件中的restrict进行说明: 下面详细对restrict进行介绍,这是一个权限控制的语句。语法如下: ask [netmask_IP] [parameter] 如果后面不加任何参数 则表示允许对面ip或ip段的任何操作。 如:restrict 127.0.0.1 常用的参数有: ignore: 拒绝所有类型的 NTP 联机; nomodify: 客户端不能使用 ntpc 与 ntpq 这两支程序来修改服务器的时间参数, 但客户端仍可透过这部主机来进行网络校时的; noquery: 客户端不能够使用 ntpq, ntpc 等指令来查询时间服务器,等于不提供 NTP 的网络校时; notrap: 不提供 trap 这个远程事件登录的功能。 notrust: 拒绝没有认证的客户端。 三、启动NTP服务 service ntpd start为了使服务可以在系统引导的时候自动启动,执行 service ntpd start chkconfig ntpd on 客户端配置 一、客户端安装ntp服务 yum install ntp ntpdate -y 二、配置ntp.conf文件 。主要是添加时间服务器的IP地址 配置文件未做特别指出则与服务器端配置一致 tinker panic 0 (这行意思是设置客户端与服务器端时间差距,默认最大为1000,为0为不限制。) server 192.168.245.128 prefer minpoll 3 maxpoll 3 (minpoll表示客户端向服务器端同步的最少时间,单位为2的次幂最小为3,秒) server 192.168.245.130 iburst minpoll 3 maxpoll 3 (maxpoll表示客户端向服务器端同步的最长时间,单位为2的次幂最大为10,秒) 三、手动同步时间 ntpdate 服务器IP或域名 检查连接是否成功 一、ntpq -p命令参数:此命令可以查看客户端和服务器端连接情况检查ntp server的防火墙。可能是server的防火墙屏蔽了upd 123端口。可以用如下命令来关掉iptables服务后再尝试从ntp客户端的同步,如果成功,证明是防火墙的问题,需要更改iptables的设置。 service iptables stop在vi /etc/sysconfig/iptables添加如下规则: -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |